﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BSU.CSCE.Services;

namespace BSU.CSCE.Web.Views
{
    public class BaseViewPage : ViewPage
    {
        public string PreviousPageLink
        {
            get
            {
                if (string.IsNullOrEmpty(Request.QueryString["back"])) return null;
                return HttpUtility.UrlDecode(Request.QueryString["back"]);
            }
        }

        public string CurrentPageBackLink
        {
            get { return HttpUtility.UrlEncode(Request.Url.AbsoluteUri); }
        }

        //public bool IsPermissionGranted(int permissionId)
        //{
        //    var administrator = new Administrator();
        //    return administrator.IsPermissionGrantedForUser(CurrentSession.CurrentUser.Id, permissionId);
        //}
    }

    public class BaseViewPage<T> : ViewPage<T> where T : class
    {
        public string PreviousPageLink
        {
            get
            {
                if (string.IsNullOrEmpty(Request.QueryString["back"])) return null;
                return HttpUtility.UrlDecode(Request.QueryString["back"]);
            }
        }
        public string CurrentPageBackLink
        {
            get { return HttpUtility.UrlEncode(Request.Url.AbsoluteUri); }
        }

        //public bool IsPermissionGranted(int permissionId)
        //{
        //    if (CurrentSession.CurrentUser != null)
        //    {
        //        var administrator = new Administrator();
        //        return administrator.IsPermissionGrantedForUser(CurrentSession.CurrentUser.Id, permissionId);
        //    }
        //    return false;
        //}
    }
}
